package gold.digger;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC921 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int minAddToMakeValid(String s) {
            Stack<Character> stack = new Stack<>();
            int needCount = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == '(') stack.push('(');
                else {
                    if (stack.isEmpty()) ++needCount;
                    else stack.pop();
                }
            }

            return needCount + stack.size();
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.minAddToMakeValid("())"));
    }

    public static void main(String[] args) throws Exception {
        LC921 an = new LC921();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
